#encoding:utf-8

from datareport.models import *
from django.db.models import Count
from db_manager import DBManager 
from redisManager import RedisManager
from config import *
from tool import Tool
import datetime
import json
import time
import sys
from wechat.models import *
from wechat.views import *


from datareport.models import *
from django.forms.models import model_to_dict  
class WechatPlatform(object):
    def __init__(self,cfgParam):
        self.cfgParam = cfgParam
        self.manager = DBManager(db,ip,ur,pd)
        self.manager.connect()
        self.tool = Tool()
        self.redisM = RedisManager()
        self.redisM.conn()
    def UserDetail(self):
        '''
	#userid detail starCount fensiCount 
	'''
        mustkeys = ["uid"]
        ret = self.tool.check_param(mustkeys,self.cfgParam) 
        if not ret["status"]:
            return ret
	
        result=RecordFile.objects.filter(uid=self.cfgParam["uid"])
	records = []
	for row in result:
	    
	    newrow = model_to_dict(row)
	    try:
	        song_info=song_base.objects.filter(song_no=newrow["songId"]).values("name","singer_names")
	        newrow["song_info"]=(song_info[0])
	    except Exception,e:
	        print e
	    newrow["recordUrl"]=RecordUrl+str(newrow["uid"])+'/'+newrow["fileName"]
	    newrow["picUrl"]= PicUrl+str(newrow["songId"])+'/'+str(newrow["songId"])+".png"
	    records.append(newrow)
	ret['records'] = records
	ret["fans"] = user_relation.objects.filter(masterid=self.cfgParam["uid"]).count()
        ret["follow"] = user_relation.objects.filter(slaveid=self.cfgParam["uid"]).count()
	
        return ret
    def SongRank(self):
        mustkeys = ["userid"]
        ret = self.tool.check_param(mustkeys,self.cfgParam) 
        if not ret["status"]:
            return ret
	mobile = self.cfgParam["userid"]
        return 	

